package oss

import (
	"jianghairui/uni-upload/appconfig"
	"path"
	"strings"
)

type QueryData struct {
	PageIndex int    `json:"pageIndex" form:"pageIndex"`
	PageSize  int    `json:"pageSize" form:"pageSize"`
	Type      string `json:"type" form:"type"`
	Search    string `json:"search" form:"search"`
	Status    string `json:"status" form:"status"`
	Date      string `json:"date" form:"date"`
	CateId    string `json:"cate_id" form:"cate_id"`
	Oriented  string `json:"oriented" form:"oriented"`
}

const RootDir string = "./static"
const Bucket string = "app-name"

var AppHost = appconfig.AppConfig.Section("").Key("app_host").String()

var AllowDir = map[string]bool{
	"tmp":    true,
	"upload": true,
}

func CheckPathPermission(path string) bool {
	prefixLinux := strings.Split(path, "/")[0]
	prefixWindows := strings.Split(path, "\\")[0]
	if !AllowDir[prefixLinux] && !AllowDir[prefixWindows] {
		return false
	}
	return true
}

func Prefix() string {
	return path.Join(RootDir, Bucket) + "/"
}

func NewQueryData() *QueryData {
	return &QueryData{
		PageIndex: 1,
		PageSize:  10,
		Type:      "",
		Search:    "",
		Status:    "",
		Date:      "",
		CateId:    "",
		Oriented:  "",
	}
}
